package com.akk.module.avs.service;

import com.akk.module.avs.entity.AvsYbLoanAccess;
import com.akk.module.avs.entity.AvsYbLoanAccessExample;
import com.akk.module.avs.mapper.AvsYbLoanAccessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AvsYbLoanAccessService {

    @Autowired
    private AvsYbLoanAccessMapper loanAccessMapper;

    @Autowired
    private AvsYbLoanAccessExample loanAccessExample;

    public List<AvsYbLoanAccess> findByParams(Map params){
        loanAccessExample.clear();
        AvsYbLoanAccessExample.Criteria criteria = loanAccessExample.createCriteria();
        if (params.containsKey("appId"))
            criteria.andAppIdEqualTo(params.get("appId").toString());
        if (params.containsKey("status"))
            criteria.andStatusEqualTo(Integer.valueOf(params.get("status").toString()));
        if (params.containsKey("startDate") && params.containsKey("endDate"))
            criteria.andCreateDateGreaterThanOrEqualTo((Date) params.get("startDate")).andCreateDateLessThanOrEqualTo((Date) params.get("endDate"));
        return loanAccessMapper.selectByExample(loanAccessExample);
    }

    public AvsYbLoanAccess findById(Long accessId){
        return loanAccessMapper.selectByPrimaryKey(accessId);
    }

    public void save(AvsYbLoanAccess access){
        loanAccessMapper.insert(access);
    }

    public void update(AvsYbLoanAccess access){
        loanAccessMapper.updateByPrimaryKey(access);
    }

    public void del(Long accessId){
        loanAccessMapper.selectByPrimaryKey(accessId);
    }



}
